package com.mayikt;

/**
 * @Author: maplefire
 * @Description:
 * @Date: 2022/08/31 17:29
 */

public class ReorderingExample {

    // 加上volatile禁止指令重排序
    int a = 0;
    boolean flag = false;

    public void write() {
        a = 1;  // 1
        flag = true;  // 2 如果flag = true先执行，i赋值为0
    }

    public void read() {
        if (flag) { // 3
            int i = a * a; // 4
        }
    }
}
